IsUserAlreadyAddedToSchool   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 14
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 12
dl 0
loc 14
rs 10
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A isSatisfiedBy 0 8 2
1
import { Inject } from '@nestjs/common';
2
import { ISchoolUserRepository } from 'src/Domain/School/Repository/ISchoolUserRepository';
3
import { SchoolUser } from 'src/Domain/School/SchoolUser.entity';
4
import { School } from '../../School/School.entity';
5
import { User, UserRole } from '../User.entity';
6
7
export class IsUserAlreadyAddedToSchool {
8
  constructor(
9
    @Inject('ISchoolUserRepository')
10
    private readonly schoolUserRepository: ISchoolUserRepository
11
  ) {}
12
13
  public async isSatisfiedBy(school: School, user: User): Promise<boolean> {
14
    if (user.getRole() === UserRole.PHOTOGRAPHER) {
15
      return true;
16
    }
17
18
    return (
19
      (await this.schoolUserRepository.findOneByUserAndSchool(user, school)) instanceof SchoolUser
20
    );
21
  }
22
}
23